package com.itsm.service.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itsm.entity.Approve;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ApproveMapper extends BaseMapper<Approve> {
    @Select("SELECT * FROM approve left join process on approve.process_no = process.process_no ")
    Approve getAll();

    //按照审批人查询最新的审批
    @Select("select * from approve where process_no = #{processNo} and approver = #{name} order by id desc , step desc,count desc limit 1")
    Approve get(String processNo,String name);

    //按照提单人查询最新的审批
    @Select("select * from approve where process_no = #{processNo} and name = #{name} and sub_time is not null order by id desc , step desc,count desc limit 1")
    Approve get2(String processNo,String name);

    @Select("select * from approve")
    List<Approve> getUserApp();

    //查询最新一条审批数据
    @Select("select * from approve where process_no = #{processNo}  order by id desc , step desc,count desc limit 1")
    Approve get1(String processNo);

    //获取最新的审批信息
    @Select("select * from approve where process_no = #{processNo} and  count = (select max(count) from approve where process_no = #{processNo}) order by id")
    List<Approve> get3(String processNo);

    //获取第二个领导的审批信息
    @Select("select * from approve where process_no = #{processNo} and count = #{count} and step = #{step} and step1 = 2 ")
    Approve select(String processNo,Integer count,Integer step);

    //查询需要几个领导审批，通过第一次审批的信息来获取
    @Select("select count(1) from approve where process_no = #{processNo} and count = 1 and step = 1 ")
    Integer getCount(String processNo);

}
